package com.dmw.controller;

import com.dmw.dto.Dto;
import com.dmw.service.ItemConsumerService;
import com.dmw.util.EmptyUtils;
import com.dmw.vo.FamilyPageVO.ItemInfoVO;
import com.dmw.vo.itemInfoVO.AddScoreVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping(value = "item/api")
public class ItemController {

    @Autowired
    private ItemConsumerService itemConsumerService;

    /**
     * 商品详情页API 6-1 根据商品id返回商品详情页
     * @param map
     * @return
     */
    @PostMapping("/p/queryItemDetail")
    @ResponseBody
    public Dto queryItemDetail(@RequestBody  Map<String, Object> map){
        System.out.println(">>>根据商品id返回商品详情页");

        System.out.println(map.get("id"));
        return itemConsumerService.queryItemDetail(map);
    }
    /**
     * 商品详情页API 6-2 根据商品ID查询商品排期
     * @param map
     * @return
     */
    @PostMapping("/p/queryItemScheduler")
    @ResponseBody
    public Dto queryItemScheduler(@RequestBody  Map<String, Object> map){
        System.out.println(">>>根据商品ID查询商品排期");
        System.out.println(map.get("itemId"));
        return itemConsumerService.queryItemScheduler(map);
    }

    /**
     * 商品详情页API 6-3 根据商品排期查询商品价格
     * @param map
     * @return
     */
    @PostMapping("/p/queryItemPrice")
    @ResponseBody
    public Dto queryItemPrice(@RequestBody  Map<String, Object> map){
        System.out.println(">>>根据商品排期查询商品价格");
        System.out.println(map.get("scheduleId"));
        return itemConsumerService.queryItemPrice(map);
    }

    /**
     * 商品详情页API 6-4 根据商品id查询剧评
     * @param map
     * @return
     */
    @PostMapping("/p/queryItemComment")
    @ResponseBody
    public Dto queryItemComment(@RequestBody  Map<String, Object> map){
        System.out.println(">>>根据商品id查询剧评");
        System.out.println(map.get("id"));
        return itemConsumerService.queryItemComment(map);
    }

    /**
     * 商品详情页API 6-5 添加剧评
     * @param vo
     * @return
     */
    @PostMapping("/v/commitItemComment")
    @ResponseBody
    public Dto commitItemComment(@RequestBody AddScoreVO vo){
        System.out.println(">>>添加剧评");
        return itemConsumerService.commitItemComment(vo);
    }

    /**
     * 商品详情页API 6-6 推荐接口
     * @param
     * @return
     */
    @RequestMapping("/p/queryItemRecommend")
    @ResponseBody
    public Dto queryItemRecommend(@RequestBody Map<String,Object> map){
        System.out.println(">>>推荐接口");
//        System.out.println(map.get("itemTypeId")+"  ??? "+map.get("limit"));
        if(map.get("itemTypeId")==null||map.get("itemTypeId").equals(""))
            map.put("itemTypeId",0);
        if(map.get("limit")==null)
            map.put("limit",5);
//        System.out.println(map.get("itemTypeId")+"  ??? "+map.get("limit"));
        return itemConsumerService.queryItemRecommend(map);
    }

    /**
     * 商品列表页API 4-2 商品搜索页查询商品分类列表
     * @return
     */
    @PostMapping("/p/type/queryItemType")
    @ResponseBody
    public Dto queryCityList(@RequestBody Map<String,Object> map){
        System.out.println(">>>商品搜索页查询商品分类列表");
        System.out.println(map.get("parent"));
        return itemConsumerService.queryItemType(map);
    }

    /**
     * 亲子首页API 8-1 查询分类接口
     * @return
     */
    @PostMapping("/p/querySlideShowPic")
    @ResponseBody
    public Dto querySlideShowPic(@RequestBody  Map<String, Object> map){
        System.out.println(">>>根据分类查询轮播图");
//        Map<String, Object> map=new HashMap<>();
//        map.put("itemTypeId",itemTypeId);
        System.out.println(map.get("itemTypeId"));
        return itemConsumerService.querySlideShowPic(map);
    }

    /**
     * 亲子首页API接口 8-2 猜你喜欢接口
     * @return
     */
    @PostMapping("/p/queryItemLike")
    @ResponseBody
    public Dto queryItemLike(@RequestBody  Map<String, Object> map){
        System.out.println(">>>猜你喜欢");
        System.out.println(map.get("itemTypeId"));
        System.out.println(map.get("limit"));
        return itemConsumerService.queryItemLike(map);
    }

    /**
     * 亲子首页API接口 8-3 精彩聚焦接口
     * @return
     */
    @PostMapping("/p/queryItemNice")
    @ResponseBody
    public Dto queryItemNice(@RequestBody  Map<String, Object> map){
        System.out.println(">>>精彩聚焦接口");
        System.out.println(map.get("itemTypeId"));
        System.out.println(map.get("limit"));
        return itemConsumerService.queryItemNice(map);
    }

    /**
     * 亲子首页API接口 8-4 根据年龄段查询节目
     * @return
     */
    @PostMapping("/p/queryItemByAge")
    @ResponseBody
    public Dto queryItemByAge(@RequestBody  Map<String, Object> map){
        System.out.println(">>>根据年龄段查询节目");
        System.out.println(map.get("ageGroup"));
        System.out.println(map.get("limit"));
        return itemConsumerService.queryItemByAge(map);
    }

    /**
     * 亲子首页API接口 8-5 根据热门城市查询热门排行
     * @return
     */
    @PostMapping("/p/queryHotCity")
    @ResponseBody
    public Dto queryHotCity(){
        System.out.println(">>>根据热门城市查询热门排行");
        return itemConsumerService.queryHotCity();
    }

    /**
     * 亲子首页API接口 8-6 根据热门城市查询热门排行
     * @return
     */
    @PostMapping("/p/queryItemHot")
    @ResponseBody
    public Dto queryItemHot(@RequestBody  Map<String, Object> map){
        System.out.println(">>>根据热门城市查询热门排行");
        System.out.println(map.get("areaId"));
        System.out.println(map.get("limit"));
        return itemConsumerService.queryItemHot(map);
    }

    /**
     * 亲子首页API接口 8-8 广告接口(图片为背景透明)
     * @return
     */
    @PostMapping("/p/queryAdvertising")
    @ResponseBody
    public Dto queryAdvertising(@RequestBody  Map<String, Object> map){
        System.out.println(">>>广告接口(图片为背景透明)");
        System.out.println(map.get("itemTypeId"));
        System.out.println(map.get("limit"));
        return itemConsumerService.queryAdvertising(map);
    }



    /**
     * 首页API-1. 获取所有的商品分类
     * @return
     */
    @PostMapping("/p/index/queryAllType")
    @ResponseBody
    public Dto queryAllType(){
        System.out.println(">>>获取所有的商品分类");
        return itemConsumerService.queryAllType();
    }

    /**
     * 首页API-2. 获取首页横向导航数据
     * @return
     */
    @PostMapping("/p/index/queryTransverse")
    @ResponseBody
    public Dto queryTransverse(){
        System.out.println(">>>获取首页横向导航数据");
        return itemConsumerService.queryTransverse();
    }

    /**
     * 首页API-3. 首页轮播图接口
     * @return
     */
    @PostMapping("/p/index/queryBanner")
    @ResponseBody
    public Dto queryBanner(){
        System.out.println(">>>首页轮播图接口");
        return itemConsumerService.queryBanner();
    }

    /**
     * 首页API-4. 今日推荐接口
     * @return
     */
    @PostMapping("/p/index/queryTodayRecommend")
    @ResponseBody
    public Dto queryTodayRecommend(){
        System.out.println(">>>今日推荐接口");
        return itemConsumerService.queryTodayRecommend();
    }

    /**
     * 首页API-5. 即将开售接口
     * @return
     */
    @PostMapping("/p/index/queryToSaleItem")
    @ResponseBody
    public Dto queryToSaleItem(){
        System.out.println(">>>即将开售接口");
        return itemConsumerService.queryToSaleItem();
    }

    /**
     * 首页API-6. 首页返回不同楼层展示数据
     * @return
     */
    @PostMapping("/p/index/queryFloorItems")
    @ResponseBody
    public Dto queryFloorItems(){
        System.out.println(">>>首页返回不同楼层展示数据");
        return itemConsumerService.queryFloorItems();
    }

    /**
     * 首页API-7. 不同分类排行
     * @return
     */
    @PostMapping("/p/index/queryHotItems")
    @ResponseBody
    public Dto queryHotItems(@RequestBody Map<String, Object> map){
        System.out.println(">>>不同分类排行");
        System.out.println(map.get("itemTypeId"));
        if (!EmptyUtils.isEmpty(map.get("itemTypeId"))){
            map.put("itemTypeId",map.get("itemTypeId").toString());
        }

        return itemConsumerService.queryHotItems(map);
    }

    /**
     * 首页API-8. 根据token返回用户信息
     * @return
     */
    @PostMapping("/p/loadCurrentUserByToken")
    @ResponseBody
    public Dto loadCurrentUserByToken(@RequestParam String token){
        System.out.println(">>>根据token返回用户信息");
        System.out.println(token);
        return itemConsumerService.loadCurrentUserByToken(token);
    }

}
